#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
from urllib.parse import quote

import requests


def add0(v):
    return v if len(v) == 2 else ('0' + v)[-2:]


v = {}
for m in range(1, 13):
    mouth = '2023年' + str(m) + '月'
    print(mouth)
    url = 'https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=39043&oe=utf8&format=json&tn=wisetpl&query=' + quote(mouth)
    r = requests.get(url)
    j = r.json()
    for d in j['data'][0]['almanac']:
        if 'status' in d:  # 1=节假日 2=工作日
            v[d['year'] + '-' + add0(d['month']) + '-' + add0(d['day'])] = int(d['status'])
        elif d['cnDay'] in ['六', '日']:
            v[d['year'] + '-' + add0(d['month']) + '-' + add0(d['day'])] = 1
        else:
            v[d['year'] + '-' + add0(d['month']) + '-' + add0(d['day'])] = 2
with open('day.py', 'w') as f:
    f.write("bd = ")
    f.write(json.dumps(v, indent=2, ensure_ascii=False))
